<?php

load_theme_textdomain('GIFPark', get_template_directory() . '/languages');

if(file_exists(STYLESHEETPATH.'/features/class.cpanel.php')){
	require_once(STYLESHEETPATH.'/features/class.cpanel.php');
	$themename	=	$WPTeamPanel->themename;
	$shortname	=	$WPTeamPanel->shortname;
	global $themename;
	global $shortname;
} else {
	wp_die(__('Theme init file not found!', 'GIFPark'));
}

if(get_option($shortname.'_admin_bar') != 'on'){
	add_filter('show_admin_bar', '__return_false');
}

function widgets_init() {
	register_sidebar( array(
		'name' => __('Left sidebar', 'GIFPark'),
		'id' => 'widgetable-area-left',
		'before_widget' => '<div id="%1$s" class="widgets %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h2>',
		'after_title' => '</h2>',
	));
	register_sidebar( array(
		'name' => __('Right sidebar', 'GIFPark'),
		'id' => 'widgetable-area-right',
		'before_widget' => '<div id="%1$s" class="widgets %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h2>',
		'after_title' => '</h2>',
	));
}
add_action( 'widgets_init', 'widgets_init' );

remove_action('wp_head', 'wp_generator');

add_theme_support('nav-menus');
register_nav_menus( array(
	'red-menu' => __('Red menu', 'GIFPark')
));

if ( function_exists( 'add_theme_support' ) ) {
	add_theme_support( 'post-thumbnails' );
        set_post_thumbnail_size(978, 99999);
}

if ( function_exists( 'add_image_size' ) ) { 
	add_image_size('slider-size',	429,	180,	true);
	add_image_size('thumb-size-1',	59,		59,		true);
	add_image_size('thumb-size-2',	215,	170,	true);
}


function get_substr($text, $words=25, $echo = true){	
	$read_more_text = "...";
	$content = strip_tags($text);
	$_ = explode(" ", $content);
	$result = "";
	if(sizeOf($_)<$len)
		$len = sizeOf($_);
	for($i=0;$i<$words-1;$i++){
		$result .= $_[$i]." ";
	}
	$result .= $read_more_text;
	if(!$echo) return $result;
	return print $result;
}



function wpt_pagenavi($before='', $after='', $echo=true) {
	$num_pages = 10;
	$stepLink = 10;
	$dotright_text = '…';
	$dotright_text2 = '…';
	$backtext = __('PrevPage', 'GIFPark');
	$nexttext = __('NextPage', 'GIFPark');
	$first_page_text = __('FirstPage', 'GIFPark');
	$last_page_text = __('LastPage', 'GIFPark');
	global $wp_query;
	$posts_per_page = (int) $wp_query->query_vars[posts_per_page];
	$paged = (int) $wp_query->query_vars[paged];
	$max_page = $wp_query->max_num_pages;
	if($max_page <= 1 ) return false;
	if(empty($paged) || $paged == 0) $paged = 1;
	$pages_to_show = intval($num_pages);
	$pages_to_show_minus_1 = $pages_to_show-1;
	$half_page_start = floor($pages_to_show_minus_1/2);
	$half_page_end = ceil($pages_to_show_minus_1/2);
	$start_page = $paged - $half_page_start;
	$end_page = $paged + $half_page_end;
	if($start_page <= 0) $start_page = 1;
	if(($end_page - $start_page) != $pages_to_show_minus_1) $end_page = $start_page + $pages_to_show_minus_1;
	if($end_page > $max_page) {
		$start_page = $max_page - $pages_to_show_minus_1;
		$end_page = (int) $max_page;
	}
	if($start_page <= 0) $start_page = 1;
	$out='';
		$out.= $before."<div class='pagination'><ul>";
			if ($backtext && $paged!=1) $out.= '<li><a href="'.get_pagenum_link(($paged-1)).'">'.$backtext.'</a></li>';
			if ($start_page >= 2 && $pages_to_show < $max_page) {
				$out.= '<a href="'.get_pagenum_link().'">'. ($first_page_text?$first_page_text:1) .'</a>';
				if($dotright_text && $start_page!=2) $out.= '<span class="extend">'.$dotright_text.'</span>';
			}
			for($i = $start_page; $i <= $end_page; $i++) {
				if($i == $paged) {
					$out.= '<li><span class="current">'.$i.'</span></li>';
				} else {
					$out.= '<li><a href="'.get_pagenum_link($i).'">'.$i.'</a></li>';
				}
			}
			if ($stepLink && $end_page < $max_page){
				for($i=$end_page+1; $i<=$max_page; $i++) {
					if($i % $stepLink == 0 && $i!==$num_pages) {
						if (++$dd == 1) $out.= '<li><span class="extend">'.$dotright_text2.'</span></li>';
						$out.= '<li><a href="'.get_pagenum_link($i).'">'.$i.'</a></li>';
					}
				}
			}
			if ($end_page < $max_page) {
				if($dotright_text && $end_page!=($max_page-1)) $out.= '<li><span class="extend">'.$dotright_text2.'</span></li>';
				$out.= '<li><a href="'.get_pagenum_link($max_page).'">'. ($last_page_text?$last_page_text:$max_page) .'</a></li>';
			}
			if ($nexttext && $paged!=$end_page) $out.= '<li><a href="'.get_pagenum_link(($paged+1)).'">'.$nexttext.'</a>';
		$out.= "</ul></div>".$after."\n";
	if ($echo) echo $out;
	else return $out;
}


if(!function_exists('display_comment_list')):
function display_comment_list( $comment, $args, $depth ) {
	$GLOBALS['comment'] = $comment;?>
	<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
		<div id="comment-<?php comment_ID(); ?>" class="comment-div">
			<span class="author"><?php comment_author(); ?></span>
			<?php comment_text(); ?>
			<?php if ( $comment->comment_approved == '0' ) : ?>
				<div class="comment-awaiting-moderation"><?php _e('Your comment is awaiting moderation.', 'GIFPark'); ?></div>
			<?php endif; ?>
		</div>
	</li>
	<?php
}
endif;

?>